package com.ctrl.riveradministrator.mvp.presenter;

import android.util.Log;

import com.ctrl.riveradministrator.base.BaseObserver;
import com.ctrl.riveradministrator.base.BasePresenter;
import com.ctrl.riveradministrator.RaApplication;
import com.ctrl.riveradministrator.mvp.model.Suggest;
import com.ctrl.riveradministrator.mvp.view.activity.suggest.SuggestView;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class SuggestPresenter extends BasePresenter<SuggestView> {

    public SuggestPresenter(SuggestView baseView) {
        super(baseView);
    }


    public void getSuggests(String pageNumb, String pageSize) {
        Map<String, String> map = new HashMap<>();
        map.put("pageNumb", pageNumb);
        map.put("pageSize", pageSize);
        attachView(apiService.getAdvice(map), new BaseObserver<Suggest>(getBaseView()) {
            @Override
            public void onSuccess(Suggest model) {
                Log.d("onSuccess", ":");
            }

            @Override
            public void onSuccess(List<Suggest> model) {
                getBaseView().showMessage(model);
            }

            @Override
            public void onFailed(String msg) {
                Log.d("onFailed", ":" + msg);
            }

        });
    }

    public void uploadSuggests(String t1,String t2){
        Map<String, String> map = new HashMap<>();
        map.put("userId", RaApplication.getUserId());
        map.put("biaoti", t1);
        map.put("neirong", t2);
        attachView(apiService.postAdvice(map), new BaseObserver<Suggest>(getBaseView()) {
            @Override
            public void onSuccess(Suggest model) {
                getBaseView().showMessage(null);
            }

            @Override
            public void onSuccess(List<Suggest> model) {
                getBaseView().showMessage(model);
            }

            @Override
            public void onFailed(String msg) {
                Log.d("onFailed", ":" + msg);
                getBaseView().showError("上传失败");
            }

        });
    }

}